// Author: Domien Nowicki

#include "ClockWidget.h"

ClockWidget::ClockWidget(QWidget *parent, ClockType type): Clock(type), QLCDNumber(parent)
{
	setNumDigits(10);
	setMinimumSize(QSize(200, 0));
	setSegmentStyle(QLCDNumber::Flat);
}

ClockWidget::~ClockWidget()
{
}

void ClockWidget::Start(int newTime)
{
	Clock::Start(newTime);

	// Start Qt timer
	timer.start(1000, this);
}

void ClockWidget::Stop()
{
	Clock::Stop();

	// Stop timer
	timer.stop();
}

void ClockWidget::UpdateDisplay()
{
	// Convert the time to a string and display it
	display(TimeToString().c_str());
}

void ClockWidget::Timeout()
{
	emit Timedout();
}

void ClockWidget::timerEvent(QTimerEvent *e)
{
	if (e->timerId() == timer.timerId()) 
	{
		// Increase time
		Tick();
	}
	else 
	{
		QWidget::timerEvent(e);
	}
}
